<?php

$uri = $_SERVER['REQUEST_URI'];
$matches = array();
$sf = ccdsSmartyFunctions::getInstance();
$ccdSQL = ccdSQL::getInstance();

if (0 < preg_match('|^/shop/[^/]*\.([0-9]+)\.([0-9]+)|',$uri,$matches)) {
	$query = "SELECT obj_id FROM import_tmp_category WHERE cat_id='".$matches[1]."'";
	$res = $ccdSQL->query($query);
	if ($row = $ccdSQL->fetch_assoc($res)) {
		$uri = $sf->smarty_link_obj(array("id" => $row['obj_id'],'lang' => 'de'));
	  header ('HTTP/1.1 301 Moved Permanently');
	  header ('Location: '.$uri);
	  die(0);
	} else {
	  header ('HTTP/1.1 301 Moved Permanently');
	  header ('Location: /');
	  die(0);
	}
	
}


if (0 < preg_match('|^/shop/[^/]*/[^/]*\.([0-9]+)\.([0-9]+)|',$uri,$matches)) {
	$query = "SELECT obj_id FROM import_tmp_product WHERE prod_simple_id='".$matches[2]."'";
	$res = $ccdSQL->query($query);
	if ($row = $ccdSQL->fetch_assoc($res)) {
		$uri = $sf->smarty_link_obj(array("id" => $row['obj_id'],'lang' => 'de'));
	  header ('HTTP/1.1 301 Moved Permanently');
	  header ('Location: '.$uri);
	  die(0);
	} else {
	  header ('HTTP/1.1 301 Moved Permanently');
	  header ('Location: /');
	  die(0);
	}
	
}

//*
//RewriteEngine On
//RewriteRule ^/shop/[^/]*\.([0-9]+)\.([0-9]+) /shop/shop-listing.php?cat_id=$1&offset=$2
//RewriteRule ^/shop/[^/]*/[^/]*\.([0-9]+)\.([0-9]+) /shop/shop-detail.php?cat_id=$1&prod_id=$2
//RewriteRule ^/lokale-shops/[^/]*\.([0-9]+) /lokale-shops/orte.php?id=$1
//
//php_admin_flag safe_mode on
//php_admin_flag register_globals Off
//php_admin_value session.auto_start 0
//php_admin_value open_basedir /usr/share/php/:/var/www/web122/html/:/var/www/web122/phptmp/:/var/www/web122/files/:/var/www/web122/atd/:/usr/share/php/smarty/:/var/www/web122/smarty/
//*/
